//管理登录状态
import {defineStore} from 'pinia'
import {UserLoginResp} from "@/api/user/types";
import {doLogout} from "@/api/user";

export const useLoginStore = defineStore('user', {
    state: () => ({
        isLogin: false,
        userId: null,
        nickName: null,
        avatar: null,

    }),
    //方法
    actions: {
        loginSuccess(loginResp: UserLoginResp) {
            this.isLogin = true
            this.userId = loginResp.id
            this.nickName = loginResp.nickname
            this.avatar = loginResp.avatar
        },
        logout() {
            doLogout().then(r => {
                this.isLogin = false
                this.userId = null
                this.nickName = null
                this.avatar = null
            })

        }
    }
})